From patchwork Thu Nov 10 07:19:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 9420947 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 93215601C0 for ; Thu, 10 Nov 2016 11:54:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F3D02962C for ; Thu, 10 Nov 2016 11:54:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73B8E2969D; Thu, 10 Nov 2016 11:54:15 +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 141AD2962C for ; Thu, 10 Nov 2016 11:54:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755599AbcKJLx5 (ORCPT ); Thu, 10 Nov 2016 06:53:57 -0500 Received: from mail-sn1nam01on0107.outbound.protection.outlook.com ([104.47.32.107]:1472 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755592AbcKJLx4 (ORCPT ); Thu, 10 Nov 2016 06:53:56 -0500 X-Greylist: delayed 15651 seconds by postgrey-1.27 at vger.kernel.org; Thu, 10 Nov 2016 06:53:55 EST 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=C5gwRChU0WY/rGPreR9FKSQfaAc4QXF73XE1VrpgReA=; b=iAk89p1/oDbYukqrUTYFfVrnWDG9XQs/0ZFTKuHOe0muaS7ynct14vZTOAgggv3vYLLJtiFKHe/BNEElApHHOhAFkoAkOozG1RyF37Qh2mEdvfE7EHfPcofBJKZ0OoHYBn7NH1F79JGZuw8kved3pTc10AKzwDc2Xo32e3msc0o= 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:19:52 +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:19:52 +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 3/3] PCI: hv: delete the device earlier from hbus->children for hot-remove Thread-Topic: [PATCH 3/3] PCI: hv: delete the device earlier from hbus->children for hot-remove Thread-Index: AdI7Is7s4N8ILPzXQNyHLjEi1hPE1A== Date: Thu, 10 Nov 2016 07:19:52 +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: cf272a64-4a4c-43db-109d-08d40939f6df x-microsoft-exchange-diagnostics: 1; MWHPR03MB2495; 7:LXhAtq9lF2bPeMQorvgY7dC4KVQAVxtM9O5ZhCTKeJOFRuiCQJJ5a6CqZoiDG5IcFBhpWr4l4UhFft+ZWJhxfjpBp68PksvG/x2y1If9aV3NyLnbDXaRzXBvMt6gKw4g6CtbaCkSvPsDqcBcT4CjUY29tphGLBBM20yxq8RKR3HxvwX6fkGVl6dYQ2vI0CU7ekC64yky7BmFsc8lxCOiFfysGRoUMUjUbwwnbDPVKVdo52ZsuOSM30OVH39E+WjZkzttr6LIpwUF05g7j+ZA4dak3cxh6sNj/iBH8rXsGMPUtxGd9T3p2Nfo9AyAg30yvOuGSp0eubOE387Y67kfqMPymQjH5ebB0A/z21zHfsepM6pkc7sZCGy2ZhdqpJ5d 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)(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:19:52.3700 (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 After we send a PCI_EJECTION_COMPLETE message to the host, the host will immediately send us a PCI_BUS_RELATIONS message with relations->device_count == 0, so pci_devices_present_work(), running on another thread, can find the being-ejected device, mark the hpdev->reported_missing to true, and run list_move_tail()/list_del() for the device -- this races hv_eject_device_work() -> list_del(). The patch moves the list_del() in hv_eject_device_work() to an earlier place, i.e. before we send PCI_EJECTION_COMPLETE, so later the pci_devices_present_work() can't see the device. Signed-off-by: Dexuan Cui CC: Jake Oshins Cc: KY Srinivasan CC: Haiyang Zhang CC: Vitaly Kuznetsov Acked-by: K. Y. Srinivasan --- drivers/pci/host/pci-hyperv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 7590ad0..fe5179d 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -1582,6 +1582,10 @@ static void hv_eject_device_work(struct work_struct *work) pci_dev_put(pdev); } + spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags); + list_del(&hpdev->list_entry); + spin_unlock_irqrestore(&hpdev->hbus->device_list_lock, flags); + memset(&ctxt, 0, sizeof(ctxt)); ejct_pkt = (struct pci_eject_response *)&ctxt.pkt.message; ejct_pkt->message_type.type = PCI_EJECTION_COMPLETE; @@ -1590,10 +1594,6 @@ static void hv_eject_device_work(struct work_struct *work) sizeof(*ejct_pkt), (unsigned long)&ctxt.pkt, VM_PKT_DATA_INBAND, 0); - spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags); - list_del(&hpdev->list_entry); - spin_unlock_irqrestore(&hpdev->hbus->device_list_lock, flags); - put_pcichild(hpdev, hv_pcidev_ref_childlist); put_pcichild(hpdev, hv_pcidev_ref_pnp); put_hvpcibus(hpdev->hbus);