From patchwork Thu Nov 10 07:18:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 9420743 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 115C8601C0 for ; Thu, 10 Nov 2016 08:53:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0990828B96 for ; Thu, 10 Nov 2016 08:53:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F262E28D84; Thu, 10 Nov 2016 08:53:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 729A828B96 for ; Thu, 10 Nov 2016 08:53:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752817AbcKJIxB (ORCPT ); Thu, 10 Nov 2016 03:53:01 -0500 Received: from mail-dm3nam03on0134.outbound.protection.outlook.com ([104.47.41.134]:15184 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752771AbcKJIxA (ORCPT ); Thu, 10 Nov 2016 03:53:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DAKMphlFYs+Z8i5P/9s5aOV+dssN2QvRPA17J+WZFSc=; b=kzRBjcXOVQQRxCQ80Z674Sj1fmnSRRCU+Ie0GIfTaVx5SufzbGmn/JgDObwdEFzHV/Lr/hKNY3+92uqNevttlb3QtdLkTK0+tXXbIfJpUIF5kf0/pW3Whukw+QappjahSQ2xuNN+ZkQiP0JL7MCMZhXVZm2QzNFfmwjgOYLnNxU= Received: from MWHPR03MB2669.namprd03.prod.outlook.com (10.168.207.15) by MWHPR03MB2495.namprd03.prod.outlook.com (10.169.201.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.707.6; Thu, 10 Nov 2016 07:18:47 +0000 Received: from MWHPR03MB2669.namprd03.prod.outlook.com ([10.168.207.15]) by MWHPR03MB2669.namprd03.prod.outlook.com ([10.168.207.15]) with mapi id 15.01.0707.006; Thu, 10 Nov 2016 07:18:47 +0000 From: Dexuan Cui To: Bjorn Helgaas , "linux-pci@vger.kernel.org" , "devel@linuxdriverproject.org" CC: "gregkh@linuxfoundation.org" , KY Srinivasan , Haiyang Zhang , "Stephen Hemminger" , Jake Oshins , "Hadden Hoppert" , Vitaly Kuznetsov , "jasowang@redhat.com" , "apw@canonical.com" , "olaf@aepfle.de" , "linux-kernel@vger.kernel.org" Subject: [PATCH 2/3] PCI: hv: fix hv_pci_remove() for hot-remove Thread-Topic: [PATCH 2/3] PCI: hv: fix hv_pci_remove() for hot-remove Thread-Index: AdI7IqyRrDR3tD1kS56J2c38IbZyTA== Date: Thu, 10 Nov 2016 07:18:47 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; x-originating-ip: [2404:f801:9000:19::66c] x-ms-office365-filtering-correlation-id: 19cdc614-357b-4b06-a4d6-08d40939d029 x-microsoft-exchange-diagnostics: 1; MWHPR03MB2495; 7:mheLyMcqX2OsAzyG60LFjGzN/EeCEJt1FhlgSh6UT3mhGlNy/dreGjDu2abuZM/Ko57vTHu2m2Kpl2xk6u1jndD0aYqv/lqkkki1ZRl8rSVZ5IugA6/tSoN8AntvWTtIzHtqJtEL9kK1wrxcuLjthfXRX0bjP8hQPLtnnzlHQgcr72akUHiLFFpidcmcjgm0y9AFmk3t6yEJq2AUJe6w4qf+Z70XEtwroI0EfNO9Sez0Emi71nfQpS3i7BEbMpJTncvNlTZVBl0tAFVAa3muBrvAywMyu4kyjbBupp/g7sYZsSHCoBmVLBbRUurI4/yTkNawfcaH7i7DE2Cq2MiUWg4KMXugd//NbxnZ6FYKR0YwQx1N509+wy5kjrTh0ACl x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:MWHPR03MB2495; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(61425038)(6045074)(6060229)(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(61426038)(61427038)(6046074)(6061226); SRVR:MWHPR03MB2495; BCL:0; PCL:0; RULEID:; SRVR:MWHPR03MB2495; x-forefront-prvs: 01221E3973 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(7916002)(189002)(199003)(33656002)(77096005)(86612001)(2501003)(9686002)(92566002)(2900100001)(8936002)(7736002)(74316002)(2906002)(6116002)(101416001)(8990500004)(586003)(102836003)(10090500001)(50986999)(76576001)(99286002)(10290500002)(5005710100001)(54356999)(105586002)(106356001)(4326007)(305945005)(5001770100001)(97736004)(3660700001)(5660300001)(87936001)(7846002)(7696004)(122556002)(2201001)(189998001)(68736007)(86362001)(575784001)(3280700002)(8676002)(81166006)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR03MB2495; H:MWHPR03MB2669.namprd03.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Nov 2016 07:18:47.4557 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR03MB2495 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 1. We don't really need such a big on-stack buffer when sending the teardown_packet: vmbus_sendpacket() here only uses sizeof(struct pci_message). 2. In the hot-remove case (PCI_EJECT), after we send PCI_EJECTION_COMPLETE to the host, the host will send a RESCIND_CHANNEL message to us and the host won't access the per-channel ringbuffer any longer, so we needn't send PCI_RESOURCES_RELEASED/PCI_BUS_D0EXIT to the host, and we shouldn't expect the host's completion message of PCI_BUS_D0EXIT, which will never come. 3. We should send PCI_BUS_D0EXIT after hv_send_resources_released(). Signed-off-by: Dexuan Cui CC: Jake Oshins Cc: KY Srinivasan CC: Haiyang Zhang CC: Vitaly Kuznetsov Acked-by: K. Y. Srinivasan --- I made the patch based on discussions with Jake Oshins and others. drivers/pci/host/pci-hyperv.c | 53 +++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 93ed64a..7590ad0 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -2266,24 +2266,32 @@ static int hv_pci_probe(struct hv_device *hdev, return ret; } -/** - * hv_pci_remove() - Remove routine for this VMBus channel - * @hdev: VMBus's tracking struct for this root PCI bus - * - * Return: 0 on success, -errno on failure - */ -static int hv_pci_remove(struct hv_device *hdev) +static void hv_pci_bus_exit(struct hv_device *hdev) { - int ret; - struct hv_pcibus_device *hbus; - union { + struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); + struct { struct pci_packet teardown_packet; - u8 buffer[0x100]; + u8 buffer[sizeof(struct pci_message)]; } pkt; struct pci_bus_relations relations; struct hv_pci_compl comp_pkt; + int ret; - hbus = hv_get_drvdata(hdev); + /* + * After the host sends the RESCIND_CHANNEL message, it doesn't + * access the per-channel ringbuffer any longer. + */ + if (hdev->channel->rescind) + return; + + /* Delete any children which might still exist. */ + memset(&relations, 0, sizeof(relations)); + hv_pci_devices_present(hbus, &relations); + + ret = hv_send_resources_released(hdev); + if (ret) + dev_err(&hdev->device, + "Couldn't send resources released packet(s)\n"); memset(&pkt.teardown_packet, 0, sizeof(pkt.teardown_packet)); init_completion(&comp_pkt.host_event); @@ -2298,7 +2306,19 @@ static int hv_pci_remove(struct hv_device *hdev) VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (!ret) wait_for_completion_timeout(&comp_pkt.host_event, 10 * HZ); +} + +/** + * hv_pci_remove() - Remove routine for this VMBus channel + * @hdev: VMBus's tracking struct for this root PCI bus + * + * Return: 0 on success, -errno on failure + */ +static int hv_pci_remove(struct hv_device *hdev) +{ + struct hv_pcibus_device *hbus; + hbus = hv_get_drvdata(hdev); if (hbus->state == hv_pcibus_installed) { /* Remove the bus from PCI's point of view. */ pci_lock_rescan_remove(); @@ -2307,17 +2327,10 @@ static int hv_pci_remove(struct hv_device *hdev) pci_unlock_rescan_remove(); } - ret = hv_send_resources_released(hdev); - if (ret) - dev_err(&hdev->device, - "Couldn't send resources released packet(s)\n"); + hv_pci_bus_exit(hdev); vmbus_close(hdev->channel); - /* Delete any children which might still exist. */ - memset(&relations, 0, sizeof(relations)); - hv_pci_devices_present(hbus, &relations); - iounmap(hbus->cfg_addr); hv_free_config_window(hbus); pci_free_resource_list(&hbus->resources_for_children);