From patchwork Mon Feb 4 15:35:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 1036019 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=yadro.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=yadro.com header.i=@yadro.com header.b="PCKufqSg"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43tWyg6jBMz9sML for ; Tue, 5 Feb 2019 02:36:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731344AbfBDPgZ (ORCPT ); Mon, 4 Feb 2019 10:36:25 -0500 Received: from mta-01.yadro.com ([89.207.88.251]:49298 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731323AbfBDPgY (ORCPT ); Mon, 4 Feb 2019 10:36:24 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id EF92F4196C; Mon, 4 Feb 2019 15:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1549294576; x=1551108977; bh=Y7bqz4DPDetczRyG4vWuemSZRvQz7iYuxkl Dbk+E/kM=; b=PCKufqSgo50tvCbks3cUJZosbl8zGShYkqUfV8zA2OExgV+8Mjg t5jQg1zUvqcZcWd/OpHS3niDZc7WN8PgMSMLGaOaumh7Il44Qxfji22fI+1hLYAY gZBSrME1hfJk3iXTnSVd4ZG9zg8wuUJ508+SDzgqXEV5Im83YWuakcLQ= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GWVQY8ui9u28; Mon, 4 Feb 2019 18:36:16 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (t-exch-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 2342641931; Mon, 4 Feb 2019 18:36:11 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.60) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Mon, 4 Feb 2019 18:36:10 +0300 From: Sergey Miroshnichenko To: CC: Bjorn Helgaas , Rajat Jain , , Sergey Miroshnichenko , , Benjamin Herrenschmidt , Oliver , Sam Bobroff , Lukas Wunner Subject: [PATCH RFC v3 06/21] PCI: Pause the devices with movable BARs during rescan Date: Mon, 4 Feb 2019 18:35:46 +0300 Message-ID: <20190204153601.7576-7-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204153601.7576-1-s.miroshnichenko@yadro.com> References: <20190204153601.7576-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.60] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Drivers indicate their support of movable BARs by implementing the new rescan_prepare() and rescan_done() hooks in the struct pci_driver. All device's activity must be stopped during a rescan, and iounmap() +ioremap() must be applied to every used BAR. Signed-off-by: Sergey Miroshnichenko --- drivers/pci/probe.c | 51 +++++++++++++++++++++++++++++++++++++++++++-- include/linux/pci.h | 2 ++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index bbc12934f041..e18d07996cf3 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -3172,6 +3172,38 @@ unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge) return max; } +static void pci_bus_rescan_prepare(struct pci_bus *bus) +{ + struct pci_dev *dev; + + list_for_each_entry(dev, &bus->devices, bus_list) { + struct pci_bus *child = dev->subordinate; + + if (child) { + pci_bus_rescan_prepare(child); + } else if (dev->driver && + dev->driver->rescan_prepare) { + dev->driver->rescan_prepare(dev); + } + } +} + +static void pci_bus_rescan_done(struct pci_bus *bus) +{ + struct pci_dev *dev; + + list_for_each_entry(dev, &bus->devices, bus_list) { + struct pci_bus *child = dev->subordinate; + + if (child) { + pci_bus_rescan_done(child); + } else if (dev->driver && + dev->driver->rescan_done) { + dev->driver->rescan_done(dev); + } + } +} + /** * pci_rescan_bus - Scan a PCI bus for devices * @bus: PCI bus to scan @@ -3185,8 +3217,23 @@ unsigned int pci_rescan_bus(struct pci_bus *bus) { unsigned int max; - max = pci_scan_child_bus(bus); - pci_assign_unassigned_bus_resources(bus); + if (pci_movable_bars_enabled()) { + struct pci_bus *root = bus; + + while (!pci_is_root_bus(root)) + root = root->parent; + + pci_bus_rescan_prepare(root); + + max = pci_scan_child_bus(root); + pci_assign_unassigned_root_bus_resources(root); + + pci_bus_rescan_done(root); + } else { + max = pci_scan_child_bus(bus); + pci_assign_unassigned_bus_resources(bus); + } + pci_bus_add_devices(bus); return max; diff --git a/include/linux/pci.h b/include/linux/pci.h index ba0b1d0ea2d2..5cd534b6631b 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -777,6 +777,8 @@ struct pci_driver { int (*resume)(struct pci_dev *dev); /* Device woken up */ void (*shutdown)(struct pci_dev *dev); int (*sriov_configure)(struct pci_dev *dev, int num_vfs); /* On PF */ + void (*rescan_prepare)(struct pci_dev *dev); + void (*rescan_done)(struct pci_dev *dev); const struct pci_error_handlers *err_handler; const struct attribute_group **groups; struct device_driver driver;