Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755616AbcKJLx6 (ORCPT ); Thu, 10 Nov 2016 06:53:58 -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 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; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" 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-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id uAABs2rD022822 Content-Length: 1935 Lines: 49 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 --- 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); -- 2.7.4